#include <bits/stdc++.h>
using namespace std;

int a[100005], c[100005], x[100005], r[100005];

int mc(int k)
{
    int ans = 1;
    for (int i = 1; i <= k; i++)
        ans *= 2;
    return ans;
}

int main()
{
    freopen("arena.in", "r", stdin);
    freopen("arena.out", "w", stdout);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= m; i++)
        cin >> c[i];
    int k = 1;
    while(mc(k) < n)
    {
        cin >> r[k];
        k++;
    }
    int t;
    cin >> t;
    for (int i = 1; i <= t; i++)
    {
        int x1, x2, x3, x4;
        cin >> x1 >> x2 >> x3;
        cout << x1 * x2 * x3 * x4;
    }

    return 0;
}